package com.aichen.starter.code.util;

import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

/**
 * @author aichen
 * @date 2022/7/5 15:00
 */
public class JavaMailSenderUtil {

    private static JavaMailSenderImpl javaMailSender;

    static {
        javaMailSender = new JavaMailSenderImpl();
        javaMailSender.setHost("smtp.qq.com");
        javaMailSender.setPort(587);
        javaMailSender.setUsername("1589054512@qq.com");
        javaMailSender.setPassword("lafszbalxgdyjfde");
        javaMailSender.setDefaultEncoding("UTF-8");
        Properties properties = new Properties();
        Properties mail = new Properties();
        Properties smtp = new Properties();
        Properties starttls = new Properties();
        properties.put("mail", mail);
        mail.put("smtp", smtp);
        smtp.put("starttls", starttls);
        starttls.put("enable", "true");
        smtp.put("socketFactoryClass", "javax.net.ssl.SSLSocketFactory");
        javaMailSender.setJavaMailProperties(properties);
    }

    public static JavaMailSender getJavaMailSender(){
        return javaMailSender;
    }
}
